package web;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class BirNearMainServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String userNum = "";
        // 检查Cookie 有时直接跳转到user
        Cookie[] cookies = req.getCookies();
        if(cookies != null)
        {
            for (Cookie cookie : cookies) {
                System.out.println(cookie.getName() + " " + cookie.getValue());
                if ("userNum".equals(cookie.getName())) {
                    userNum = cookie.getValue();
                }
            }
        }


        if (userNum == "") {
            // 跳转404
            resp.sendRedirect("/webdemo2/views/loginDemo.html");
        } else {
            // 转发请求到userinfo
            resp.sendRedirect("/webdemo2/views/nearuserbir.html");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }

}
